<?php
class Slidebar_model extends CI_Model {    
    function __construct()
    {
        parent::__construct();
    }
    //$query->free_result(); 
    function get_happening($limit=16){
        $this->db->limit($limit);
        $this->db->order_by('id','DESC');
        $this->db->select(
                            'credit.*,
                            users.username,
                            offer.title,
                            network.title as nettitle
                            
                            ');
        $this->db->from('credit');
        $this->db->join('users', 'users.id = credit.iduser','left'); 
        $this->db->join('offer', 'offer.id = credit.idoff','left');   
        $this->db->join('network', 'network.id = credit.idnet','left');     
        $query = $this->db->get();        
        return $query->result();
    }
    function get_lastcredited($limit=16){
        $this->db->group_by('credit.idoff'); 
        $this->db->group_by('credit.idnet');
        $this->db->limit($limit);
        $this->db->order_by('id','DESC');
        $this->db->select(
                            'credit.*,                            
                            offer.title                                                   
                            ');
        $this->db->from('credit');
        $this->db->join('offer', 'offer.id = credit.idoff','left');   
        $query = $this->db->get();        
        return $query->result();
    }
    function get_lastadded($limit=16){
        $this->db->limit($limit);
        $this->db->where('show',1);
        $this->db->select(array('title','point','id'));
        $this->db->order_by('id','DESC');
        $query = $this->db->get('offer');        
        return $query->result();
    } 
}